package com.huijutao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.huijutao.MyApp;
import com.huijutao.R;
import com.huijutao.beans.HcYouHui;

import java.util.ArrayList;

/**
 * Created by Administrator on 2015/4/24.
 */
public class HcYouhuiAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<HcYouHui> datas;
    private LayoutInflater inflater=null;

    public HcYouhuiAdapter(Context context, ArrayList<HcYouHui> datas) {
        this.context = context;
        this.datas = datas;
    }

    @Override
    public int getCount() {
        if(datas!=null)
            return datas.size();

        return 0;
    }

    @Override
    public Object getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder=null;
        inflater=LayoutInflater.from(context);
        if (convertView==null){
            convertView=inflater.inflate(R.layout.fragment_hc_listview,null);
            holder=new Holder();
            holder.image = (ImageView) convertView.findViewById(R.id.hc_Item_image);
            holder.text_price = (TextView) convertView.findViewById(R.id.hc_Item_price);
            holder.text_shop = (TextView) convertView.findViewById(R.id.hc_Item_shop);
            holder.text_time = (TextView) convertView.findViewById(R.id.hc_Item_time);
            holder.text_title = (TextView) convertView.findViewById(R.id.hc_Item_title);
            convertView.setTag(holder);

        }else {
            holder= (Holder) convertView.getTag();
        }

        HcYouHui you=datas.get(position);
        holder.text_price.setText(you.getSubtitle());
        holder.text_shop.setText(you.getGo_websit());
        holder.text_time.setText(you.getTime());
        holder.text_title.setText(you.getTitle());
        MyApp.mImageXutils.display(holder.image, you.getImg_path());
        return convertView;
    }

    class Holder {
        ImageView image;
        TextView text_title;
        TextView text_price;
        TextView text_time;
        TextView text_shop;

    }
}
